package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.LoginRecordBean;
import com.project.bean.UserBean;
import com.project.service.ILoginRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("loginRecord")
@Api(tags = "登录日志控制层")

public class LoginRecordController {
    @Autowired
    private ILoginRecordService loginRecordService;
    /**
     * 分页动态查询日志信息
     * 输入：页码，起始日期，结束日期
     * 处理：分页动态查询日志信息
     * 输出：分页对象
     * 日志信息：日志编号，日期，日志内容
     * @param pageNum
     * @param startDate
     * @param endDate
     * @return
     */
    @ApiOperation(value = "分页动态查询日志信息")
    @GetMapping("cutFindByItem")
    public IPage<LoginRecordBean> cutFindByItem(Integer pageNum, LocalDate startDate, LocalDate endDate){
        return loginRecordService.cutFindByItem(pageNum, startDate, endDate);
    };

    /**
     * 添加登录日志
     * @param username
     */
    @ApiOperation(value = "添加登录日志")
    @PostMapping("add")
    public String add(String username){
        System.out.println(username+"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
        LoginRecordBean loginRecordBean = new LoginRecordBean("用户"+username+"在"+ LocalDate.now()+"登录了系统");
        loginRecordService.add(loginRecordBean);
        return "ok";
    };
}
